package com.atguigu.eduservice.controller;


import com.atguigu.eduservice.entity.subject.OneSubject;
import com.atguigu.eduservice.service.EduSubjectService;
import common.atguigu.commonutils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-05-31
 */
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
@Api("课程分类管理类")
public class EduSubjectController {
    @Autowired
    private EduSubjectService subjectService;

    //添加课程分类，获取上传过来的文件夹，把文件内容读取出来
    @PostMapping("addSubject")
    public R addSubject(@ApiParam(name = "file", value = "课程分类表格文件", required = true)
                                MultipartFile file) {
        //上传过来excel文件
        subjectService.saveSubject(file, subjectService);
        System.out.println("haha");
        return R.ok();
        //fddf

    }
    //获取课程分类列表（树形）
    @GetMapping("getAllSubject")
    public R getAllSubjecct() {
        //list集合泛型是一级分类
        List<OneSubject> list = subjectService.getAllSubject();
        return R.ok().data("list", list);
    }
}
